﻿using Syspetro.Core.AppDeal;
using Syspetro.Core.CommandBus;
using Syspetro.Core.SysInterface;

namespace Syspetro.Core.Encrypt
{
    /// <summary>
    /// 校验密码
    /// </summary>
    public class PswdCheckCommand : Command
    {
        public string Pswd { get; set; }
        public string Account { get; set; }
        public string Md5Pswd { get; set; }
    }
    public interface IPswdCheckCommandHandler : ICommandHandler<PswdCheckCommand>, ITransientService
    {

    }
    public class PswdCheckCommandHandler : CommandHandler<PswdCheckCommand>, IPswdCheckCommandHandler
    {
        private const string slat = "bj";
        public override SpActionResult<string> Execute(PswdCheckCommand command)
        {
            if (string.IsNullOrEmpty(command.Pswd))
                return new SpActionResult<string> { Success = false, Msg = "密码不能为空" };
            else
            {
                string pswd = MD5Helper.MD5Encrypt64(command.Pswd + command.Account + slat);
                if (pswd.Equals(command.Md5Pswd))
                    return new SpActionResult<string>("密码校验通过");
                else
                    return new SpActionResult<string> { Success = false, Msg = "密码错误" };
            }
        }
    }
}
